#ifndef MAINDIALOG_H
#define MAINDIALOG_H

#include <BMenu>
#include <BButton>
#include <BCheckBox>
#include <BSlider>
#include <BTableWidget>
#include <BTreeWidget>
#include <BRealSpinBox>
#include <BViewer>
#include <BCamera>
#include <BScene>
#include <BImage>
#include <BMainWindow>

#include "FileDialog.h"
#include "OrganizeDialog.h"
#include "ModifyDialog.h"
#include "PropertyBoard.h"
#include "CameraPanel.h"
#include "MyHandler.h"

using namespace BWE;

class MainWindow : public BMainWindow
{
	BOBJECT(MainWindow)
public:
	MainWindow();
	~MainWindow();

	bool openFile(const BString& fileName);

protected:
	void initMenus();
	const char* primName(Primitive prim);
	BString findValidName(const BScene* scene, const BString& name);
	BString findValidName(const BGroup* group, const BString& name);
	BString findValidName(const BNode* node, const BString& name);
	BIcon* typedIcon(const BObject* object);
	BObject* copyObject(const BObject* object);
	void freshMenuIcons(BMenu* menu);
	BTreeItem* createTreeItem(BScene* scene);
	BTreeItem* createTreeItem(BGroup* group);
	BTreeItem* createTreeItem(BNode* node);
	BTreeItem* createTreeItem(BShape* shape);
	BTreeItem* createTreeItem(BConstraint* constraint);
	void removeTreeItem(BTreeItem* item);

protected:
	void slotImportButtonClicked();
	void slotExportButtonClicked();
	void slotResetButtonClicked();
	void slotmodifyButtonClicked();

	void slotCreateGroupActionTriggered(BObject* object, const BValue& value);
	void slotCreateNodeActionTriggered(BObject* object, const BValue& value);
	void slotCreateShapeActionTriggered(BObject* object, const BValue& value);
	void slotOrganizeMenuTriggered(BObject* object, const BValue& value);
	void slotCopyActionTriggered(BObject* object, const BValue& value);
	void slotCutActionTriggered(BObject* object, const BValue& value);
	void slotPasteActionTriggered(BObject* object, const BValue& value);
	void slotRenameActionTriggered(BObject* object, const BValue& value);
	void slotRemoveActionTriggered(BObject* object, const BValue& value);

	void slotNameEditFocused(BObject* object, const BValue& value);
	void slotFrameChecked();
	void slotLightingChecked();
	void slotShowNormalsChecked();
	void slotNormalLengthEdited();
	void slotGridLineVisibleChecked(BObject* object, const BValue& value);
	void slotGrdiSizeEditFinished(BObject* object, const BValue& value);
	void slotGridSegmentEditFinished(BObject* object, const BValue& value);
	void slotGridColorButtonClicked();
	void slotTreeItemClicked(BObject* object, const BValue& value);
	void slotTreeRightClicked(BObject* object, const BValue& value);
	void slotViewerRightClicked(BObject* object, const BValue& value);

	void slotTargetSelected(BObject* object, const BValue& value);
	void slotDeleteTarget(BObject* object, const BValue& value);
	void slotSceneSpaceChanged(BObject* object, const BValue& value);
	void slotSceneInserted(BObject* object, const BValue& value);
	void slotSceneRemoved(BObject* object, const BValue& value);
	void slotNodeRenamed(BObject* object, const BValue& value);

protected:
	virtual void adjustEvent(const BEvent& event);

	virtual void styleEvent(const BEvent& event);

private:
	BButton*			_importButton;
	BButton*			_exportButton;
	BButton*			_resetButton;
	BButton*			_viewButton;
	BButton*			_modifyButton;

	BCheckBox*			_frameCheckBox;
	BCheckBox*			_lightingCheckBox;
	BCheckBox*			_showNormalsCheckBox;
	BSlider*			_normalLengthSlider;
	BGroupBox*			_gridLinesGroupBox;
	BRealSpinBox*		_gridSizeSpinBox;
	BSpinBox*			_gridSegmentSpinBox;
	BButton*			_gridColorButton;

	BTreeWidget*		_sceneTree;
	BViewer*			_viewer;
	PropertyBoard*		_propertyBoard;
	CameraPanel*		_cameraPanel;

	BLineEdit*			_nameEdit;
	BMenu*				_itemMenu;
	BMenu*				_viewerMenu;
	FileDialog*			_fileDialog;
	OrganizeDialog*		_organizeDialog;
	ModifyDialog*		_modifyDialog;

	BCamera*			_camera;
	MyHandler*			_handler;
	BScene*				_scene;
	BHolder<Target>		_target;
};

#endif